package inv.stask.ui;

import inv.stask.beans.Task;
import inv.stask.logic.TaskUtil;

import java.awt.Component;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;

public class DateCellRenderer extends TaskRowRenderer {
	private static final long serialVersionUID = 6328059101955354418L;
	
	public DateCellRenderer() {
		super();
		setText("---");
		setIconTextGap(4);
		setVerticalTextPosition(SwingConstants.CENTER);
		setHorizontalTextPosition(SwingConstants.LEFT);
	}
	
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		Component c	= super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		if(value != null && value instanceof Task){
			Task task	= (Task)value;
			if(c instanceof JLabel){
				((JLabel)c).setText(TaskUtil.shortFormat.format(task.getDueDate()));
				DateCellEditor.updateButtonOnWeekend((JLabel)c, task.getDueDate());
				DateCellEditor.updateButtonOnDeadline((JLabel)c, task.getDueDate(), task.getDone());
				DateCellEditor.updateButtonPostoned((JLabel)c, task.getPostponed());
			}
		}
		return c;
	}
	
	@Override
	public void setFont(Font font) {
		super.setFont(font);
	}

}
